'''
Created on 18 dec. 2011

@author: Daan
'''
from argparse import ArgumentError

class Lane(object):
    '''
    classdocs
    '''
    def __init__(self, lengths, parts):
        '''
        Constructor
        '''
        self.lengths = lengths
        self.parts = parts
        self._lengthDefined = 0
        
    def GetPart(self, pos):
        length = 0
        i = 0
        
        for l in self.lengths :
            if pos <= (length + l) :
                percentage = 0
                pos = pos - length
                
                return (self.parts[i], pos)
            i += 1
            length += l
        
        return (None, percentage)
    
    def GetPartOffset(self, part):
        if part > len(self.parts):
            raise ArgumentError("parts", "Out of Range")
        
        if 0 == part:
            return 1
        
        return sum(self.lengths[x] for x in range(part)) + 1
        
    def GetLength(self):
        if self._lengthDefined == 0:
            for l in self.lengths:
                self._lengthDefined += l
        return self._lengthDefined
        
        
        
